package com.soft.jdbc.student.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/6/6
 */
public class C3P0Util {
    private static final ComboPooledDataSource dataSource = new ComboPooledDataSource("mysql");

    // 获取数据源
    public static DataSource getDataSource() {
        return dataSource;
    }

    // 获取连接
    public static Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }

    // 释放连接
    public static void close(Connection connection) {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
